package com.dm.frontend.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dm.common.utils.DubboUtil;

import com.dm.details.service.DetailsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("details")
public class DetailsController {

    @Reference(url = DubboUtil.DUBBO_URL_DETAILS,version = DubboUtil.VERSION_1, group = DubboUtil.GROUP_NAME)
    private DetailsService detailsService;

    @RequestMapping("query/all")
    public String queryAll(Model model){
        List<DmItem> dmItems = detailsService.queryAll();
        model.addAttribute("getAll", dmItems);
        return "details/test3";
    }

    @RequestMapping("query/item/{id}")
    public String queryItem(@PathVariable("id")Long id, Model model){
        DmItem dmItems = detailsService.queryItemById(id);
        model.addAttribute("getItems", dmItems);
        return "details/list";
    }


    @RequestMapping("add/order")
    public String addOrder(DmUser dmUser, DmItem dmItem){
        DmOrder dmOrder = new DmOrder();
        dmOrder.setUserId(dmUser.getId());
        dmOrder.setItemId(dmItem.getId());
        detailsService.addOrder(dmOrder);
        return "";
    }


}
